package com.xumx.demo.service;

import com.xumx.demo.pojo.Order;
import com.xumx.demo.repository.OrderRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class OrderService {

    @Autowired
    private OrderRepository orderRepository;


    public Order add(Order order) {

        Order order1 = new Order();
        Order order2 = new Order();
        // 把order2中的数据复制一份到order1中
        BeanUtils.copyProperties(order1, order2);

        return orderRepository.save(order);
    }

    public List<Order> find(Order order) {
        if (1 == 1) {
            throw new RuntimeException("异常啦");
        }
        return orderRepository.findByUserId(order.getUserId());
    }

    public Optional<Order> findById(Order order) {
        return orderRepository.findById(order.getOrderId());
    }

}
